const path = require('path')
const { proxy, define } = require('./build/cli')
const debug = process.env.NODE_ENV !== 'production'
console.log('输出为本地--------------------pp',process.env.NODE_ENV)
const server = {
    dev: {
        api:"http://192.168.0.119:9998",
        domain:"http://192.168.0.119:9998",
        // api:"https://192.168.0.109:8080",
        // domain:"https://192.168.109.88:8080",
        // api:"https://192.168.0.119:8080",
        // domain:"https://192.168.0.119:8080",
    },
    // prod: {
    //     api: "https://backstage.ztkuaichong.com:3001",
    //     domain: "https://backstage.ztkuaichong.com:3001"
    // },
    prod: {
        api: "https://192.168.0.119:3001",
        domain: "https://192.168.0.119:3001"
    }
}
module.exports = {
    publicPath: '/', // 根域上下文目录
    outputDir: 'dist', // 构建输出目录
    assetsDir: 'assets', // 静态资源目录 (js, css, img, fonts)
    lintOnSave: false, // 是否开启eslint保存检测，有效值：ture | false | 'error'
    runtimeCompiler: true, // 运行时版本是否需要编译
    transpileDependencies: [], // 默认babel-loader忽略mode_modules，这里可增加例外的依赖包名
    productionSourceMap: false, // 是否在构建生产包时生成 sourceMap 文件，false将提高构建速度
    configureWebpack: config => { // webpack配置，值位对象时会合并配置，为方法时会改写配置
        if (debug) { // 开发环境配置
            config.devtool = 'cheap-module-eval-source-map'
            config.externals = {
                AMap: "AMap", //加这个！！
                AMapUI: "AMapUI"
              }
        } else { // 生产环境配置
        }
    },
    chainWebpack: config => { // webpack链接API，用于生成和修改webapck配置，https://github.com/vuejs/vue-cli/blob/dev/docs/webpack.md
        if (debug) {
            // 本地开发配置
        } else {
            // 生产开发配置
        }
    },
    chainWebpack: config => {
         // 移除 prefetch 插件
      config.plugins.delete('prefetch')
      // 定义 process.env
      config.plugin('define').tap(args => {
        Object.keys(define).forEach(k => (args[0]['process.env'][k] = JSON.stringify(define[k])))
        return args
      })
    },
    parallel: require('os').cpus().length > 1, // 构建时开启多进程处理babel编译
    pluginOptions: { // 第三方插件配置
    },
    pwa: { // 单页插件相关配置 https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-pwa
    },
    devServer: {
        open: true,
        // disableHostCheck: true,
        // host: '127.0.0.1',
        host: '0.0.0.0',
        port: 8080,
        https: false,
        hotOnly: false,
        proxy: {
            '^/api': {
                target: server.dev.api,
                timeout:90000,
                secure: false,
                changeOrigin: true,
                pathRewrite: { '^/api': '/' }
            },
            '^/wethers': {
                target: 'http://www.nmc.cn',
                timeout:90000,
                secure: false,
                changeOrigin: true,
                pathRewrite: { '^/wether': '/' }
            }
        },
        before: app => { }
    }
}
